<template>
	<view class="center">
		<u-sticky>
			<baseNavbarHome title="关注列表" />
		</u-sticky>
		<view class="deh" v-for="item in followNode" :key="item.id">
			<view @tap="jumpContact(item)" class="deh-box">
				<image :src="item.user.userProfileImg" mode="" class="deh-left">
				</image>
				<view class="deh-right">
					<view class="name">{{ item.user.username }}</view>
					<view class="time">
						荔知游ID：{{ item.user.uuid.length < 10 ? item.user.uuid : address2simple(item.user.uuid, 4) }}
					</view>
				</view>
			</view>
			<view class="but" @click="cancel(item.followingUuid)">
				取消关注
			</view>
		</view>

		<view v-if="followNode.length <= 0" class="emptyBox">
			<view class="empty">
				<image src="../../static/my/empty.png"></image>
				<view>什么都没有～</view>
			</view>
		</view>

		<!-- 弹窗 -->
		<u-popup :show="payClose" @close="payClose = false" bgColor="transparent" mode="center" :overlay="false">
			<view class="poput-box fontS28 padding_l_r40">
				<view class="bold color_222222 text-center mar_top60">确认不再关注？</view>
				<view class="flex justify-between align-center mar_top60 mar_bottom30">
					<view @click="payClose = false"
						class="point-out border color-46CA28 flex justify-center align-center ">取消</view>
					<view @click="onAffirm"
						class="point-out bg_color_E5725F color_fff flex justify-center align-center">
						确定</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script setup>
	import baseNavbarHome from '@/components/base-navbar-home.vue'
	import {
		ref,
		getCurrentInstance
	} from "vue";

	import {
		onReady,
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	const {
		proxy
	} = getCurrentInstance();
	
	const followNode = ref([]);
	const fans = async () => {
		const res = await proxy.$api.care()
		console.log(res.data, 'data-userProfileImg')
		followNode.value = res.data
	}
	const address2simple = (address, cut) => {
		let length = address.length;
		if (!address || length < cut * 2) {
			return "";
		}
		let prefix = address.substring(0, cut);
		let suffix = address.substring(length - cut, length);
		return `${prefix}...${suffix}`;
	}

	const payClose = ref(false);
	const followingUuid = ref('');

	const cancel = (id) => {
		followingUuid.value = id;
		payClose.value = true;
	}
	const jumpContact = (item) => {
		uni.navigateTo({
			url: `/pages/my/contactHomePage?id=${item.user.uuid}`
		})
	}

	const onAffirm = async () => {
		const res = await proxy.$api.fool2({
			followingUuid: followingUuid.value
		})
		payClose.value = false;
		fans()
	}

	onShow(() => {
		fans()
	})
</script>

<style lang="scss" scoped>
	.center {
		min-height: 100vh;
		background: #f8f8f8;
	}

	.deh {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		box-sizing: border-box;
		height: 96rpx;
		margin-top: 50rpx;
		padding-bottom: 40rpx;
		box-sizing: border-box;
		border-bottom: 1rpx solid #f8f8f8;
	}

	.deh-box {
		display: flex;
		align-items: center;
	}

	.deh-left {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		margin-right: 16rpx;
	}

	.deh-right {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.name {
		font-size: 30rpx;
	}

	.time {
		font-size: 26rpx;
	}

	.but {
		width: 128rpx;
		height: 56rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		border: 2rpx solid #6d6d6d;
		border-radius: 32rpx;
		font-family: PingFang SC;
		font-size: 28rpx;
		font-weight: 500;
		color: #6d6d6d;
		margin-left: 10rpx;
		text-align: center;
	}

	.border {
		border: 2rpx solid #6D6D6D;
	}

	.poput-box {
		width: 474rpx;
		min-height: 242rpx;
		background: #FFFFFF;
		box-shadow: 0 16rpx 40rpx 0 rgba(0, 0, 0, 0.2);
		border-radius: 20rpx;

		.point-out {
			width: 160rpx;
			height: 56rpx;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
		}
	}

	.emptyBox {
		position: absolute;
		transform: translate(-50%,-50%);
		top: 50%;
		left: 50%;

		.empty {
			width: 228rpx;
			margin: 0 auto;
			font-family: PingFang SC;
			font-size: 24rpx;
			font-weight: 400;
			color: #6D6D6D;
			display: flex;
			flex-wrap: wrap;
			justify-content: center;

			image {
				width: 228rpx;
				height: 268rpx;
				margin-bottom: 30rpx;
			}
		}
	}
</style>